package com.getpebble.android.framework.protocol.inbound;

import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.framework.protocol.EndpointId;
import com.google.common.primitives.UnsignedInteger;
import java.nio.ByteBuffer;

public class PblInboundPutBytesMessage extends PblInboundMessage {
    private UnsignedInteger mCookie;
    private PutBytesResponse mResponse;

    public enum PutBytesResponse {
        ACK((byte) 1),
        NACK((byte) 2);
        
        private byte mId;

        private PutBytesResponse(byte id) {
            this.mId = id;
        }

        public byte getId() {
            return this.mId;
        }

        public static PutBytesResponse fromId(byte id) {
            for (PutBytesResponse response : values()) {
                if (response.getId() == id) {
                    return response;
                }
            }
            return null;
        }
    }

    public PblInboundPutBytesMessage(ProtocolMessage message) {
        super(message);
        ByteBuffer buffer = message.getDataBuffer();
        this.mResponse = PutBytesResponse.fromId(buffer.get());
        this.mCookie = UnsignedInteger.fromIntBits(buffer.getInt());
    }

    public PutBytesResponse getResponse() {
        return this.mResponse;
    }

    public UnsignedInteger getCookie() {
        return this.mCookie;
    }

    public EndpointId getId() {
        return EndpointId.PUT_BYTES;
    }

    protected int getMinSize() {
        return 5;
    }
}
